#include <algorithm>
#include <iostream>
using namespace std;

const int kMaxN = 1010;
const int kInf = 1e9;

int h[kMaxN];

int main() {
  freopen("skidesign.in", "r", stdin);
  freopen("skidesign.out", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  int min_cost = kInf;
  for (int minH = 0, maxH = 17; maxH <= 100; minH++, maxH++) {
    int cost = 0;
    for (int i = 0; i < n; i++) {
      if (h[i] < minH) {
        cost += (minH - h[i]) * (minH - h[i]);
      } else if (h[i] > maxH) {
        cost += (h[i] - maxH) * (h[i] - maxH);
      }
    }
    min_cost = min(min_cost, cost);
  }
  cout << min_cost << "\n";
  return 0;
}